﻿using System;
using System.Collections.Generic;
using System.Linq;

using System.Web.Mvc;
using Prodma.DataAccess.Database;
using Prodma.DataAccess.Models;
using Prodma.DataAccess.Helper.Enumerators;
using Prodma.DataAccess.Models.ViewModels;

namespace Prodma.DataAccess.DataService.ListService
{
    public static class AuthorizationList
    {

        private static DataContext context = new DataContext();

        public static IList<LoginUser> GetLoginUserList()
        {
            return (IList<LoginUser>)System.Web.HttpContext.Current.Application["loginUserList"];
        }

        public static AuthorizationVm GetAuthorizationList(int roleId, int menuId)
        {
            DataContext context = new DataContext();
            using (context)
            {
                var authorization = (from auth in context.tb_Authorization
                                     where auth.tb_MenuAdmin.Id == menuId &&
                                           auth.tb_Role.Id == roleId
                                     select new AuthorizationVm()
                                     {
                                         Read = auth.Read,
                                         Write = auth.Write,
                                         Update = auth.Update,
                                         Delete = auth.Delete
                                     }).FirstOrDefault();

                return authorization;
            }
        }
    }
}
